package page_handle

import (
	"data-system/models"
	"fmt"
)

type PageLogicHandler interface {
	Handle() (models.PageLogicHandleCtx, error)
}

type handlerFunc func(ctx models.PageLogicHandleCtx) (PageLogicHandler, error)

var handlers = map[string]handlerFunc{
	"def_logic_key": NewPageLogicArrHandleCtx,
}

func RouteHandler(ctx models.PageLogicHandleCtx) (PageLogicHandler, error) {
	method, ok := handlers[ctx.Meta.Key]
	if ok {
		handler, err := method(ctx)
		if err != nil {
			return nil, err
		}
		return handler, nil
	} else {
		return nil, fmt.Errorf("没有页面逻辑处理器：key=%v", ctx.Meta.Key)
	}
}
